
<?php

if (isset($_GET['url'])) {
  
$url = $_GET['url'];
$curla = curl_init($url);

curl_setopt($curla, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curla, CURLOPT_HEADER, true);
curl_setopt($curla, CURLOPT_NOBODY, true);

// 执行cURL请求
$response = curl_exec($curla);

// 获取响应头信息
$header_size = curl_getinfo($curla, CURLINFO_HEADER_SIZE);

// 关闭cURL资源


// 提取Content-Length响应头信息
$content_length = 0;
if ($header_size !== false) {
    $header = substr($response, 0, $header_size);
    if (preg_match('/Content-Length: (\d+)/', $header, $matches)) {
        $content_length = (int)$matches[1];
    }
}
$c = '1024';
$k = $content_length;
$f = $content_length/2;

curl_setopt($curla, CURLOPT_URL, "https://mini.s-shot.ru/".$c."x".$k."/PNG/".$f."/?".$url);
curl_setopt($curla, CURLOPT_HEADER, 0);
$ht = curl_exec($curla);
$screenshotUrl = "https://mini.s-shot.ru/{$c}x{$k}/PNG/{$f}/?" . $url;
echo $screenshotUrl;
} else {
    echo "参数 Url 缺失";
}
